
const app = getApp().globalData
import {newsList } from '../../../api/news'
Page({
  data: {
    //https://nhkj.it-cn.cn/"
    list: [],
    finished: false,
    key:'',
    page: 1,
    formMark: false,
    tabIdx: 0,
  },
  onLoad() {
   this.getList()
  },
  onShow() {
    this.getList()
  },
  toggleTab(e) {
    const { idx } = e.currentTarget.dataset
    this.data.page = 1
    this.data.finished = false
    this.setData({
      formMark: false,
      list: [],
      tabIdx: idx
    })
    //this.getList()
  },
  getList() {
    newsList({pageNum: this.data.page, pageSize: 20, programName: this.data.key}).then((res) => {
      wx.stopPullDownRefresh()
      this.setData({
        formMark: true,
        list: this.data.page > 1 ? this.data.list.concat(res.datas) : res.datas
      })
      if (this.data.list.length >= res.total) {
        this.data.finished = true
      }
    })
  },
  onPullDownRefresh() {
    this.data.finished = false
    this.data.page = 1
    this.getList()
  },
  onReachBottom() {
    if (this.data.finished) {
      return
    }
    this.data.page++
    this.getList()
  },
  gopage(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  }
})